// index.ts
// 获取应用实例
const app = getApp<IAppOption>()
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
import { getTodoList } from '../../services/mockData';

Page({
  data: {
    userName: '张三',
    todoCount: 0,
    todoList: [],
    approvalTypes: [
      {
        id: 1,
        name: '请假申请',
        icon: '🏖️'
      },
      {
        id: 2,
        name: '报销申请',
        icon: '💰'
      },
      {
        id: 3,
        name: '出差申请',
        icon: '✈️'
      },
      {
        id: 4,
        name: '采购申请',
        icon: '🛒'
      }
    ]
  },

  onShow() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0
      });
    }
    this.loadTodoList();
  },

  async loadTodoList() {
    const todoList = await getTodoList();
    this.setData({ 
      todoList,
      todoCount: todoList.length
    });
  },

  goToCreateApproval(e: any) {
    const { type } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/createApproval/createApproval?type=${type}`
    });
  },

  goToDetail(e: any) {
    const { id } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/approvalDetail/approvalDetail?id=${id}`
    });
  }
});
